package com.ksu.manager.dao.ibatisImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import com.ksu.manager.dao.IItemManagerDAO;
import com.ksu.manager.model.ItemManager;
import com.ksu.manager.model.pages.Pagination;
import com.ksu.manager.util.PageQuery;



public class ItemManagerDAOImpl extends SqlSessionDaoSupport implements IItemManagerDAO {

	@SuppressWarnings("unchecked")
	public Map<String,Object> queryList(ItemManager itemManager,Pagination page) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		try {
            int sum = ((Integer)this.getSqlSession().selectOne("itemManager.selectCount", itemManager)).intValue();
            RowBounds rowBounds = new RowBounds(page.getStartNumber(), page.getPageNumber()); 
            List<ItemManager> itemManagerList = (List<ItemManager>)this.getSqlSession().selectList("itemManager.select",itemManager,rowBounds);
            resultMap = PageQuery.query(page, sum, itemManagerList);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}
	
	
	public void create(ItemManager itemManager) {
		try {
			this.getSqlSession().insert("itemManager.insert",itemManager);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	public void del(ItemManager itemManager) {
		try {
			this.getSqlSession().delete("itemManager.delete",itemManager);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}


	public void update(ItemManager itemManager) {
		try {
			this.getSqlSession().update("itemManager.update",itemManager);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
